package org.efficientsoap.client;

import android.app.ProgressDialog;
import android.os.AsyncTask;

public class ProgressAsyncTask extends AsyncTask<String, Integer, String>{
	 ProgressDialog dialog;
	 
	  
	 @Override
	 protected void onPreExecute() {
	  // Setup Progress Dialog
	  dialog = new ProgressDialog(null);
	  dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
	  dialog.setMax(100);
	  dialog.show();
	 }
	 
	 @Override
	 protected String doInBackground(String... params) {
	 
	  // updateProgress Dialog and dismiss the Dialog when it's done
	  for (int i = 0; i < 50; i++){
	   publishProgress(2);
	   try {
	    Thread.sleep(100); // wait 100ms
	   } catch (InterruptedException e) {
	    e.printStackTrace();
	   }
	  }
	  dialog.dismiss();
	  return null;
	 }
	 
	 @Override
	 protected void onProgressUpdate(Integer... values) {
	  // Increment Progress Dialog with the Update 
	                // from the doInBackgroundMethod
	  dialog.incrementProgressBy(values[0]);
	 }
	 
}
